layui.extend({
    baseConfig : "/js/pages/baseConfig"
})
layui.use(['form','layer','laydate','table','laytpl','element','util','baseConfig'],function(){

    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        baseConfig = layui.baseConfig,
        table = layui.table;
    var util = layui.util;
    var tableIns = table.render({
        elem: '#list',
        url : "/userAdmin/list/",
        text: { none: "Aucun résultat"},
        cellMinWidth : 95,
        height : "full-125",
        id : "listTable",
        cols : [[
            {type: "checkbox", fixed:"left", width:50},
            {field: 'reviewStatus', title: "状态", align:"center", templet : function( d){
                    switch ( d.reviewStatus) {
                        case "PASS": return "<span style='color: green;'>审核通过<span>";
                        case "REJECT": return "<span style='color: red;'>审核拒绝<span>";
                        case "DEFAULT": return "<span>未审核<span>";
                        default: return "未审核";
                    }
            }},
            {field: 'roleName', title: "员工角色", align:"center", templet : function( d){
                return d.role.roleName;
            }},
            {field: 'jobNumber', title: "员工工号", align:"center"},
            {field: 'prenom', title: "员工名", align:"center"},
            {field: 'nom', title: "员工姓", align:"center", templet : function( d){
                if( d.nomNumber){
                    return d.nom + d.nomNumber;
                }
                return d.nom;
            }},
            {field: 'createTimeStr', title: '申请时间', align:'center'},
            {title: 'État', width:600, templet:'#listBar',fixed:"right", align:"center",templet : function( d) {
                var str = "<a class=\"layui-btn layui-btn-xs layui-btn-danger\" lay-event=\"mooncardCardAdmin\">Mooncard银行余额设置</a>\n";
                return str;
            }}
        ]],
        response : {
            statusCode: 200 //规定成功的状态码，默认：0
        },
        parseData : function( res){ //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.length, //解析数据长度
                "data": res.data //解析数据列表
            };
        }
    });

    //获取浏览器最大高度，以防页面显示不完全
    var maxHeight = $(window).height();

    //mooncard银行卡管理
    function mooncardCardAdmin( data){
        var index = layui.layer.open({
            title : "员工[" + data.jobNumber + "]Mooncard银行卡余额设置",
            type : 2,
            area: [650 + 'px', (maxHeight < 500 ? maxHeight - 10 : 500) + 'px'],
            shade: 0.4,
            btnAlign: 'r',
            id:  "userBalanceInfo", //设定一个id，防止重复弹出
            content : "mooncardCardList.html?adminUserId=" + data.id,
            success : function(){
                var body = layui.layer.getChildFrame( 'body', index);
                form.render();
                setTimeout( function(){
                    layui.layer.tips('点击此处返回数据列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                },500);
            }
        });
    }

    //列表操作
    table.on('tool(list)', function(obj){
        var layEvent = obj.event,
            data = obj.data;
        if(layEvent === 'mooncardCardAdmin'){
            mooncardCardAdmin( data);
        }
    });
});
